package com.sdc.controller;

import com.sdc.model.User;
import com.sdc.service.UserService;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/user")
@EnableAutoConfiguration
@RestController
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("save")
    public Map<String, Object> save(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
        request.setCharacterEncoding("UTF-8");
        User user = new User();
        user.setName(request.getParameter("username"));
        userService.save(user);
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        Map<String, Object> result = new HashMap<>();
        result.put("resp_code", "0000");
        result.put("resp_msg", "SUCCESS");
        return result;
    }
}
